<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 10/2/18
 * Time: 8:25 PM
 */
/**
 * @var \yii\web\View $this
 * @var \common\models\db\DocuComment $model
 * @var \home\modules\docu\models\FormCommentReply $form_reply
 * @var \yii\data\ActiveDataProvider $replyDataProvider
 */

use kartik\form\ActiveForm;
use common\components\tools\Html;
use yii\widgets\ListView;
use common\rewrite\widgets\LinkPager;
use kriss\wangEditor\WangEditorWidget;
?>

<div class="row">
    <div class="col-xs-12">
        <!-- Comment -->
        <div class="media media-comment-list">
            <?php echo $model->createdBy->getProfileBoxA($model->createdBy->getAvatarImg(64, 64, ['class' => "media-object img-circle"]), ['class' => "pull-left"]) ?>
            <div class="media-body">
                <h4 class="media-heading">
                    <?=$model->createdBy->getProfileBoxA($model->createdBy->profileName) ?>
                    <small><?=date("Y-m-d H:i", $model->created_at) ?></small>
                    <small class="pull-right">
                        <?php if (Yii::$app->user->isGuest): ?>
                            <?= \home\models\FormLogin::getLoginBoxA("请登陆后回复") ?>
                        <?php else: ?>
                            <?=Html::button('回复', ['class' => "comment_reply_btn btn btn-xs"]) ?>
                        <?php endif; ?>
                    </small>
                </h4>
                <?=$model->body ?>
                <hr>
                <!-- Nested Comment -->
                <?=ListView::widget([
                    'dataProvider' => $replyDataProvider,
                    'itemView' => function($model) {
                        return $this->render('_reply_list', ['model' => $model,]);
                    },
                    'layout' => '{items}{summary}{pager}',
                    'itemOptions' => ['class' => "reply_list_box"],
                    'pager' => [
                        'class' => LinkPager::class,
                        'go' => true,
                    ],
                ]) ?>
                <?php if (Yii::$app->user->isGuest): ?>
                <?php else: ?>
                    <div class="media media-reply-form" style="display: none;">
                        <div class="media-body">
                            <?php $reply_form = ActiveForm::begin(['options' => ['data-pjax' => true,]]); ?>
                            <?=$reply_form->field($form_reply, 'comment_id')->hiddenInput(['value' => $model->id])->label(false) ?>
                            <?=$reply_form->field($form_reply, 'parent_id')->hiddenInput()->label(false) ?>
                            <?=$reply_form->field($form_reply, 'at_user')->hiddenInput()->label(false) ?>
                            <?php // $reply_form->field($form_reply, 'body')->widget(WangEditorWidget::class, [])->label(false) ?>
                            <?php echo $reply_form->field($form_reply, 'body')->textarea()->label(false) ?>
                            <?=$reply_form->field($form_reply, 'code')->widget(\yii\captcha\Captcha::class)->label(false) ?>
                            <?= Html::submitButton('回复', ['class' => "btn btn-primary"]) ?>
                            <?php ActiveForm::end(); ?>
                        </div>
                    </div>
                    <br>
                <?php endif; ?>
                <!-- End Nested Comment -->
            </div>
        </div>
    </div>
</div>
